package com.wolf.gulimall.search.controller;


import com.netflix.client.http.HttpRequest;
import com.wolf.gulimall.search.service.MallSearchService;
import com.wolf.gulimall.search.vo.SearchParam;
import com.wolf.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Autowired
    private MallSearchService mallSearchService;


    @GetMapping("/list.html")
    public String listPage(SearchParam searchParam, Model model, HttpServletRequest httpServletRequest) {
        //根据参数,在es中查询数据并返回渲染
        searchParam.setQueryString(httpServletRequest.getQueryString());
        SearchResult result = mallSearchService.search(searchParam);
        model.addAttribute("result", result);
        return "list";
    }
}
